#include"csapp.h"

typedef struct
{
int maxfd;
fd_set read_set;
fd_set ready_set;
int nready;
int maxi;
int clientfd[FD_SETSIZE];
rio_t clientrio[FD_SETSIZE];
}pool;

int byte_cnt = 0;

int main(int argc,char **argv)
{
int listenfd,connfd,port;
socklen_t clientlen = sizeof(struct sockaddr_in);
struct sockaddr_in clientaddr;
static pool;

if(argc !=2)
{
fprintf(stderr,"usage:%s<port>\n",argv[0]);
exit(0);
}
port = atoi(argv[1]);

listenfd=Open_listenfd(port);
init_pool(listenfd,&pool);  //初始化池，之后服务器进入一个无线循环
while(1)
{
pool.ready_set=pool.read_set;
pool.nready=Select(pool.maxfd+1,&pool.ready_set,NULL,NULL,NULL);

if(FD_ISSET(listenfd,&pool.ready_set)){  //连接请求到达
connfd=Accept(listenfd,(SA *)&clientaddr,&clientlen);
add_client(connfd,&pool);  //将该客户端添加到池里
}

check_clients(&pool);  //把来自每个准备好的已连接描述符的一个文本行送回去
}
}
